/**
* Created by ren on 2017/1/6.
*/
<template>
  <div class='opinions'>
    <textarea placeholder="请输入您的宝贵意见（500字以内）" v-model="content"></textarea>
    <button class="btn" :disabled="disabled" @click="saveFeedBack"
            style="float: right;width: 120px;height: 40px;border-radius: 0;color: white;margin-top: 50px;background: #f48315">
      提交
    </button>
    <Notify :parentThis='this'></Notify>
  </div>
</template>

<script>
  import API from '../../api'
  import Notify from '../Notify'
  export default {
    name: 'opinions',
    components: {
      Notify
    },
    props: ['_parentThis'],
    data: function () {
      return {
        notifyStatus: 2,
        content: '',
        disabled: true
      }
    },
    methods: {
      saveFeedBack: function () {
        this.$http.post(API.saveFeedBack, {
          userId: this.$cookie.get('id'),
          content: this.content
        }).then((ret) => {
          const result = ret.body
          if (result.code === 1) {
            this.notifyStatus = '1|意见反馈成功，谢谢您的反馈'
            this.content = ''
          } else {
            this.notifyStatus = '0|' + result.message
          }
        }, (err) => {
          console.log(err)
        })
      }
    },
    mounted: function () {
      this._parentThis.cutName = 'opinions'
    },
    watch: {
      content: function (newVal) {
        if (newVal !== '') {
          this.disabled = false
        } else {
          this.disabled = true
        }
      }
    }
  }
</script>
